package com.example.Handler;

import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;


/*
* 可以在 HandlerThread中的Handler里用文本信息,可以用它来下载图片，和异步任务差不多，
* 但是比异步任务更省时
* */
public class HandlerThreadActivity extends AppCompatActivity {
TextView textView;
    HandlerThread handlerThread;
    Handler handler;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        textView=new TextView(this);
        setContentView(textView);
        handlerThread=new HandlerThread("handler Thread");
        handlerThread.start();
        handler=new Handler(handlerThread.getLooper()){

            @Override
            public void handleMessage(Message msg) {
                textView.setText("handler Thread");

                System.out.println("current - - - - ->"+Thread.currentThread());

            }
        };
        handler.sendEmptyMessage(1);
    }
}
